package cn.open.feishu.alert.common.utils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

/**
 * @Description 时间工具类
 * @Author fandy.lin
 * @Date 2021/11/23 10:30 上午
 **/
public class TimeUtil {
    /**
     * 获取当前时间前几秒
     *
     * @param mintues
     * @return
     */
    public static Date getRecentMinute(Date now, Integer mintues) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(now);
        calendar.add(Calendar.MINUTE, mintues);
        return calendar.getTime();
    }

    /**
     * 当前时间格式化成常规时间串
     *
     * @return
     */
    public static String currentDateFormat() {
        return dateFormat(System.currentTimeMillis());
    }

    /**
     * 时间格式化成常规时间串
     *
     * @return
     */
    public static String dateFormat(Long timestamp) {
        Date now = new Date(timestamp);
        String format = "yyyy-MM-dd HH:mm:ss";
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        return sdf.format(now);
    }

    /**
     * date格式化成utc时间串
     *
     * @return
     */
    public static String dateFormatUtc(Date date) {
        String format = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
        return sdf.format(date);

    }
}